//
//  SettingViewCell.swift
//  TimMusic
//
//  Created by nkl on 2024/10/11.
//

import Foundation
import UIKit

class SettingViewCell<T: BasicCellModelProtocol>: UITableViewCell {
    lazy var bgView: UIView = {
        let v: UIView = .simpleView(color: .clear)
        v.layer.borderColor = UIColor.white.withAlphaComponent(0.4).cgColor
        v.layer.borderWidth = 1
        v.layer.cornerRadius = 16
        v.layer.masksToBounds = true
        return v
    }()

    lazy var nameLabel: UILabel = .simpleLabel(text: "Test", font: .systemFont16, color: .white)
    lazy var tipLabel: UILabel = .simpleLabel(text: "tips", font: .systemFont16, color: .white)

    lazy var arrowImgView: UIImageView = .simpleImage(imageName: "ic_setting_arrow")

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        addChildren()
        makeConstraints()
    }

    func bindData(model: SettingModel) {
        nameLabel.text = model.type.rawValue
        if model.type == .about {
            arrowImgView.isHidden = true
            tipLabel.text = AppDelegate.currentVersion
            tipLabel.isHidden = false
        } else {
            arrowImgView.isHidden = false
            tipLabel.isHidden = true
            tipLabel.text = ""
        }
    }

    func addChildren() {
        selectionStyle = .none
        backgroundColor = .clear
        contentView.backgroundColor = .clear
        addSubview(bgView)
        bgView.addSubview(nameLabel)
        bgView.addSubview(arrowImgView)
        bgView.addSubview(tipLabel)
    }

    func makeConstraints() {
        bgView.snp.makeConstraints { make in
            make.horizontalEdges.equalToSuperview().inset(16)
            make.verticalEdges.equalToSuperview().inset(5)
        }
        nameLabel.snp.makeConstraints { make in
            make.leading.equalToSuperview().offset(16)
            make.centerY.equalToSuperview()
            make.trailing.equalToSuperview().offset(-16)
        }
        arrowImgView.snp.makeConstraints { make in
            make.trailing.equalToSuperview().offset(-16)
            make.centerY.equalToSuperview()
            make.width.height.equalTo(24)
        }

        tipLabel.snp.makeConstraints { make in
            make.trailing.equalToSuperview().offset(-16)
            make.centerY.equalToSuperview()
            make.height.equalTo(24)
        }
    }

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
